#!/bin/bash
#--------------------------------------------------------------------------
printf "\n\tPackages to build cloonix will be installed.\n\n"
#--------------------------------------------------------------------------
if [ ! -e /etc/os-release ]; then 
  printf "\n\tERROR: Not able to determine your distribution."
  printf "\n\tYou must install the packages by hand.\n\n"
  exit
fi
#--------------------------------------------------------------------------
name=$(cat /etc/os-release |grep PRETTY_NAME)
name=${name#*\"}
name=${name%% *}
#--------------------------------------------------------------------------
if [ -z $name ]; then
  printf "\n\tERROR: Not able to determine your distribution from os-release."
  printf "\n\tYou must install the packages by hand.\n\n"
  exit
fi
#--------------------------------------------------------------------------
fct_get_debian_packages()
{
  apt-get -y install tar build-essential pkg-config intltool libtool \
                     rxvt-unicode autoconf libncurses5-dev coreutils \
                     libopus-dev libjpeg-dev libusb-1.0-0-dev libgtk-3-dev \
                     openssl libssl-dev libcap-dev libevent-dev \
                     libreadline-dev python3 python3-pyparsing python3-six \
                     libepoxy-dev libgstreamer-plugins-base1.0-dev \
                     libgbm-dev libpolkit-gobject-1-dev libacl1-dev \
		     sudo zlib1g-dev liborc-0.4-dev libegl1-mesa-dev \
                     libdrm-dev bison flex libjson-glib-dev libsasl2-dev \
                     libnuma-dev libpixman-1-dev libpcap-dev libmnl-dev \
                     libibverbs-dev xorriso ninja-build meson wireshark 
case "$name" in
  "Ubuntu")
   apt-get -y install linux-headers-generic
  ;;

  *)
   apt-get -y install linux-headers-amd64
  ;;
esac

}
#--------------------------------------------------------------------------
fct_get_redhat_packages()
{
  dnf -y install \
         tar xorriso xterm make gcc gcc-c++ m4 bc glibc-devel libtool \
         libstdc++-devel intltool ncurses-devel libjpeg-turbo-devel \
         pkg-config autoconf cyrus-sasl-devel openssl openssl-devel \
         gtk3-devel libcap-devel libevent-devel readline-devel python3 \
         python3-six gstreamer1-plugins-base-devel libepoxy-devel \
         polkit-devel libacl-devel dejavu-serif-fonts orc-devel \
         mesa-libEGL-devel bison flex wireshark libusbx-devel bzip2 \
         python3-pyparsing numactl-devel kernel-headers meson \
         json-glib-devel mesa-libgbm-devel opus-devel 

# meson ninja
}
#--------------------------------------------------------------------------
fct_get_opensuse_packages()
{
  zypper --non-interactive install \
         tar xorriso rxvt-unicode make gcc gcc-c++ m4 bc glibc-devel \
         libtool libstdc++-devel intltool ncurses-devel libjpeg62-devel \
         patch pkg-config autoconf cyrus-sasl-devel openssl openssl-devel \
         gtk3-devel libcap-devel libevent-devel readline-devel python3 \
         python3-six gstreamer-plugins-base-devel libepoxy-devel \
         polkit-devel libacl-devel orc-devel libusb-1_0-devel \
         Mesa-libEGL-devel bison flex wireshark python3-pyparsing \
         libnuma-devel kernel-headers json-glib-devel \
         libgbm-devel libopus-devel rxvt-unicode xorriso \
         meson ninja
}
#--------------------------------------------------------------------------
if [ $UID != 0 ]; then
  printf "\n\tERROR: root privileges needed to install packages.\n\n"
  exit
fi
case "$name" in
  "Debian" | "Ubuntu" | "Kali")
    printf "\n\tInstall tool is apt-get.\n\n"
    apt-get --assume-yes update
    fct_get_debian_packages
  ;;
  "Red" | "CentOS" | "Fedora")
    printf "\n\tInstall tool is dnf.\n\n"
    dnf update -y
    fct_get_redhat_packages
  ;;
  "openSUSE")
    printf "\n\tInstall tool is zypper.\n\n"
    zypper update -y
    fct_get_opensuse_packages
  ;;
  *)
  printf "\n\tERROR: Your distribution: $name is not supported"
  printf "\n\tYou must install the packages by hand.\n\n"
  exit
  ;;
esac
#--------------------------------------------------------------------------



